const sqlite3 = require('sqlite3').verbose();
const path = require('path');

// 创建数据库连接
const dbPath = path.join(__dirname, 'fushen.db');
const db = new sqlite3.Database(dbPath, (err) => {
  if (err) {
    console.error('Error opening database:', err.message);
  } else {
    console.log('Connected to the SQLite database.');
    checkDocuments();
  }
});

function checkDocuments() {
  // 查询所有文档
  const sql = 'SELECT * FROM documents';
  db.all(sql, [], (err, rows) => {
    if (err) {
      console.error('Error querying documents:', err.message);
    } else {
      console.log('Documents in database:');
      console.log(rows);
      
      // 查询所有用户
      const userSql = 'SELECT * FROM users';
      db.all(userSql, [], (err, userRows) => {
        if (err) {
          console.error('Error querying users:', err.message);
        } else {
          console.log('Users in database:');
          console.log(userRows);
        }
        
        // 关闭数据库连接
        db.close((err) => {
          if (err) {
            console.error('Error closing database:', err.message);
          } else {
            console.log('Database connection closed.');
          }
        });
      });
    }
  });
}